import { Token } from '@/types/data'
import { LoginAction } from '@/types/store'
import { getToken } from '@/utils/storage'
// 注意
// const initValue: Token = {} as Token
const initValue: Token = getToken()

export default function login(state = initValue, action: LoginAction) {
  if (action.type === 'login/login') {
    return action.payload
  }
  if (action.type === 'login/logout') {
    // 清除redux token
    return {
      token: '',
      refresh_token: '',
    }
  }
  return state
}
